﻿using Nintex.Workflow;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Workflow.ComponentModel;

namespace NintexX
{
    [Serializable]
    public abstract class NintexXAction
    {
      
        public NWWorkflowContext NintexWorkFlowContex { get; set; }
        
        protected void SetWorkflowVariableValue(string name,object value)
        {
            _SetWorkflowVariableValue(NintexWorkFlowContex.CurrentActivity, name, value);
        }

        private static void _SetWorkflowVariableValue(Activity activity, string valueName, object value)
        {
            if (activity != null)
            {
                try
                {
                    ActivityBind workflowActivityBind = new ActivityBind();
                    workflowActivityBind.Name = activity.Name;
                    workflowActivityBind.Path = valueName;
                    workflowActivityBind.SetRuntimeValue(activity, value);
                }
                catch
                { }
                _SetWorkflowVariableValue(activity.Parent, valueName, value);
            }
        }

        public abstract void Execute(Hashtable workflowVariables, string inputParam);
    }
}
